<?php

namespace Admin\Controller;

use Think\Controller;

class CaseController extends ExtendController {

    //显示栏目
    public function index(){
     $list = D('CaseType')->order('sort asc')->select();
     if(!empty($list)){
       $this->assign('list',$list);
        
     }
     $this->display(); // 输出模板
    }
   
   public function insert(){
    $this->display();
   }
   public function add(){
    $data['t_name']=$_POST['title'];
    $data['sort'] = $_POST['sort'];
    $data['createtime'] = date('Y-m-d H:i:s');
    
     $result = D('CaseType')->add($data);
            if ($result != false) {
            $this->redirect('Case/index');
        } else {
            $this->error('删除失败!');
        }

   }


         //修改
     public function update() {
        if(IS_POST){
                $where['t_id'] = $_POST['id'];
                    $data['t_namse'] = $_POST['title'];
                    $data['sort'] = $_POST['sort'];
                    $data['createtime'] =date('Y-m-d H:i:s');
                    $result = D('CaseType')->where($where)->save($data);
                    if ($result != false) {
                        $this->redirect('index');
                    } else {
                        $this->error('非法操作!');
                    }
        }else{
            //获取到该条记录的内容
             $list= D('CaseType')->where('t_id = '.$_GET['id'])->find();
             if(!$list){
                $this->error('非法操作!');
             }
             $this->assign('list',$list);
                $this->display('update');
                }
}

    //删除
    public function delete() {
        $imagesModel = M('CaseType');
        $map['t_id'] = $_GET['id'];
        $result = $imagesModel->where($map)->delete();
        if ($result) {
            $this->redirect('Case/index');
        } else {
            $this->error('删除失败!');
        }
    }
}